from pms.common.views import PostFormula
from department.utils import assert_department_permissions
from department.models import Work
from department.utils.member import department_member_view


class API(PostFormula):

    def handle(self, req):
        assert_department_permissions(self.user.id, req['did'], [3])
        work = Work.objects.get(uid_id=req['uid'], rid__did_id=req['did'])
        view = department_member_view(work)
        work.delete()
        return self.success_respond(view)
